var page = require('webpage').create();
var system = require('system');

address = system.args[1];
passwd = system.args[2];

page.onLoadFinished =  function() {
    console.log(page.content)
    console.log('<==========>')
    var cookies = page.cookies;
    console.log(JSON.stringify(cookies))
    console.log('<==========>')
    var passwdEncrpt = page.evaluate(function(passwd) {
        document.getElementById('txtPW').value = passwd
        pwobj=document.getElementById('txtPW')
        codeobj=document.getElementById('txtCode')
        CFSKey = CFS(pwobj.value)
        EnCryptData = CFSKey + codeobj.value
        return MD5(EnCryptData)
    }, passwd);
    console.log(passwdEncrpt)
    console.log('<==========>')
    phantom.exit(0);
}

page.settings.userAgent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_3) ALLL/537 (KHTML, like Gecko) Chrome/46.0.2924.87 Safari/537.36"

page.open(address, function (status) {
    if (status !== 'success') {
        phantom.exit(0);
    } else {
        setTimeout(function(){
            phantom.exit(0)
        }, 5000)
    }
});
